package group6renderer.renderernode;

import group6renderer.Display;
import group6renderer.HTMLConstants;


/** ClASS NAME: ListIndexNode
 * DESCRIPTION: A class to deal with the indexing of lists
 * COLABORATORING CLASSES: BranchNode, Display, HTMLConstants
 * @author jonnie
 */
public class ListIndexNode  extends BranchNode {
    
	Integer index=0;
    
	/**
	 * A Constructor to initialise the fields of a new ListIndexNode.
	 */
    public ListIndexNode(String name)
    {
    	this.name=name;

    }
    
    /** 
     * A method to return whether this Node is a LeafNode
     * @return true if this node has a closing tag and false otherwise
     */
    public boolean isLeaf()
    {
	return false;
    }

    /** 
     * A method to return whether this Node has a closing tag
     * @Override
     * @return true if this node has a closing tag and false otherwise
     */
    public boolean hasClosing()
    {
    	return true;
    }

    /**
    * A method to set the index.
    * @param num the number to set the index to
    */
    
    public void setIndex(int num)
    {
    	index=num;
    }


    /** 
     * A method overriding the abstract method in TreeNode. It adjusts the properties of the State class according to the type of node
     * concerned.  
     * @param disp the Display object of the project (there is only one)
     * @Override
     */
    public void drawNode(Display disp)
    {
    	
    	if (goingDown && !isCopy)
    	{
        	if (lineChange1())
        		disp.crlf();
        	else
    		{disp.crlf();disp.crlf();}
        	getIndex();
        	String indexString="";
        	if (index==0) indexString="*";
        	else
        	indexString=index.toString();
        	disp.getState().toggleState(name);
        	disp.getState().setListIndex(indexString);
        	
        }
  else if (!goingDown && !copied)
    	{
	  		disp.getState().toggleState(name);	
	  		
	  		if (lineChange2())
	  			disp.crlf();
	  		else
	  		{	disp.crlf();disp.crlf();}
	  		
	  		
    //	maybe the above things are needed
    	
    	}

    	goingDown=!goingDown;
    	
    	
    	
    	
    	
    }
    //maybe it needs fixing
    
    /** 
     * A method to return a new copy of this node.
     * @Override
     * @return a new instance of this node with the original name
     */
    public TreeNode copy()
    {
	return new ListIndexNode(name);
    }
    
    /**
     * A method to get the index.
     */
    public void getIndex()
    {
    	TreeNode parent=this.parent;
    	

    	
    	
    	while(parent!=null)
    	{
    		
    		if (parent.getName()==HTMLConstants.ORDLIST)
    		{
    			ListNode l=(ListNode)parent;
    			index=l.addIndexNode(this);
    			break;
    		}
    		
    		parent=parent.parent;
    	}
    		
    }
    

}
